function fp2real (d:fixsign; top:integer; low:integer) 
return real is
  variable outreal : real := 0.0;
  variable mult : real := 1.0;
  variable max : real := 1.0;
  variable debug : boolean := false;
begin
  for i in 0 to top-1 loop
    if d(i) = '1' then
      outreal := outreal + mult;
      if debug  then
        report "  fp2real : " & integer'image(i);
      end if;
    end if;
    mult := mult * 2.0;
  end loop;
  if debug  then
    REPORT " fp2real middle : " & real'image(outreal);
  end if;
  max := mult;
  mult := 0.5;
  for i in -1 downto low loop
    if d(i) = '1' then
      outreal := outreal + mult;
      if debug  then
        report "  fp2real : " & integer'image(i);
      end if;
    end if;
    mult := mult * 0.5;
  end loop;
  if debug then
    REPORT " fp2real : " & real'image(outreal);
  end if;
		
  if d(top) = '1' then
    outreal := outreal - max;
  end if;
  if debug then
    REPORT " fp2real FINAL VALUE : " & real'image(outreal);
  end if;

  return outreal;
end;